Component({
  properties: {},
  data: {
    keybord3: [
      "0",
      "1",
      "2",
      "3",
      "4",
      "5",
      "6",
      "7",
      "8",
      "9",
      "a",
      "b",
      "c",
      "d",
      "e",
      "f",
      "g",
      "h",
      "j",
      "k",
      "l",
      "m",
      "n",
      "o",
      "p",
      "q",
      "r",
      "s",
      "t",
      "u",
      "v",
      "w",
      "x",
      "y",
      "z",
      "学",
      "澳",
      "港",
    ],
    keybord1: [
      "0",
      "1",
      "2",
      "3",
      "4",
      "5",
      "6",
      "7",
      "8",
      "9",
      "a",
      "b",
      "c",
      "d",
      "e",
      "f",
      "g",
      "h",
      "j",
      "k",
      "l",
      "m",
      "n",
      "o",
      "p",
      "q",
      "r",
      "s",
      "t",
      "u",
      "v",
      "w",
      "x",
      "y",
      "z",
      "学",
      "澳",
      "港",
    ],
    keybord2: [
      "京",
      "津",
      "沪",
      "渝",
      "苏",
      "浙",
      "豫",
      "粤",
      "川",
      "陕",
      "冀",
      "辽",
      "吉",
      "皖",
      "闽",
      "鄂",
      "湘",
      "鲁",
      "晋",
      "黑",
      "赣",
      "贵",
      "甘",
      "桂",
      "琼",
      "云",
      "青",
      "蒙",
      "藏",
      "宁",
      "新",
      "使",
      "领",
      "警",
      "港",
      "澳",
      "台",
      "学"
    ],
    value: ["", ""],
    value1: ['', "", "", "", "", ""],
    show: false,
    show1: false,
    focusid: -1,
    focus: false,
    focusIndex: 0,
    titleAfter: false,
    endIndex: 0,
    isSelect: false,
    endLen: null,
    twoTitle:''
  },
  methods: {

    getFocus12() {
      // ////console.log(1111);
      this.setData({
        focus: true
      })
    },



    inputListener(e) {
      ////console.log(e);
      let {
        index
      } = e.currentTarget.dataset
      if (this.data.focusIndex != index) {
        this.setData({
          focusIndex: index
        })
      }
      if (index < 6) {
        this.setData({
          focus: true,
          focusIndex: Number(Number(index) + 1)
        })
        ////console.log(this.data.focusIndex);
      } else {
        this.setData({
          focus: false
        })
      }
    },

    getIndex(e) {
      console.log(e);
      let {
        index,item
      } = e.currentTarget.dataset
      console.log(item);
      let {
        value1
      } = this.data;

      let keybord3 = this.data.keybord3;

      for (let index = 0; index < keybord3.length; index++) {
        keybord3[index] = keybord3[index].toUpperCase();
      }

      this.setData({
        endIndex: index,
        focusIndex: 2,
        show: true,
        keybord3: keybord3,
        twoTitle:item || ''
      });
    },

    putKey(e) {
      console.log(e);
      
      let {
        key,
        id,
        idx = 1
      } = e.currentTarget.dataset;

      //判断是否第二位键盘输入，执行不可为。返回效果
      if (id === "1") {
        if (idx < 10) {
          console.log('署出来');
          return
        }

        if (idx > 35) {
          console.log('署出来');
          return
        }
      }
      if(id === "2"){
        if (idx > 35) {
          console.log('署出来');
          return
        }
      }


      let {
        value,
        value1
      } = this.data;
      let that = this;
      let list = [];
      let keybord1 = this.data.keybord1;
      let keybord3 = this.data.keybord3;
      for (let index = 0; index < keybord1.length; index++) {
        keybord1[index] = keybord1[index].toUpperCase();
      }
      for (let index = 0; index < keybord3.length; index++) {
        keybord3[index] = keybord3[index].toUpperCase();
      }
      this.setData({
        keybord1: keybord1,
        keybord3: keybord3,
      });
      if (key == 110) {
        if (that.data.endIndex == 6) {
          that.setData({
            titleAfter: false
          })
        }

        if (value1.length == 0 && that.data.focusIndex >= 2) {
          let list457 = that.data.value;
          list457.pop();
          that.setData({
            focusIndex: 1,
            value:list457
          });
          return
        }else if(that.data.focusIndex == 1) {
          let list457 = that.data.value;
          list457.pop();
          that.setData({
            focusIndex: 0,
            value:list457
          });
          return
        }
        if (value1) {
          list = that.data.value1;
          list.pop();
          value1 = list;
          // endIndex: --that.data.endIndex
          that.setData({
            value1,
            endIndex: value1.length
          });
        }
        if (value1[5] == undefined) {
          that.setData({
            titleAfter: false
          })
        }
        //console.log(value1[5]);
      } else if (id) {
        key = key.toUpperCase();
        if (id == 1) {
          value[id] = key;
          that.setData({
            value,
            focusIndex: 2,
          });
        } else if (id == 2) {
          if (that.data.endIndex > 5) {
            return
          }
          value1[that.data.endIndex] = key;
          value1.map((it, index) => {
            for (let index1 = index; index >= 0; index--) {
              if (index < index1) {
                if (value1[index] == undefined) {
                  value1[index] = ''
                }
              }
            }
          })
          let length = value1.filter((it) => {
            return it != ''
          })
          if (this.data.endIndex == 5) {
            that.setData({
              titleAfter: true
            })
          }
          if (this.data.endIndex == 5 && value1[5] == '') {
            that.setData({
              titleAfter: false
            })
          }
          console.log(key);
          that.setData({
            value1,
            endIndex: ++that.data.endIndex,
            twoTitle:key
          });
        } else {
          value[id] = key;
          that.setData({
            value,
            focusIndex: 1
          });


        }
      }
      this.getLength()

    },
    getLength() {
      let key1 = this.data.value.length
      let key2 = this.data.value1.length
      let endLen = key1 + key2
      if (endLen >= 7) {
        this.setData({
          isSelect: true,
        })
        this.triggerEvent('conmitTag', this.data.isSelect);
      } else {
        this.setData({
          isSelect: false,
        })
        this.triggerEvent('conmitTag', this.data.isSelect);

      }
    },
    show(e) {
      console.log(e,'--------');
      let {
        item,
        index
      } = e.currentTarget.dataset;
      let value = this.data.value;
      if (value[index] == undefined) {
        // value[index] = "";
        if (index == 1) {
          if (value[0] == undefined) {
            value[0] = "";
          }

        }
        this.setData({
          focusIndex: index
        })
      } else {
        // value[index] = "";
        this.setData({
          focusIndex: index
        })
      }
      let keybord1 = this.data.keybord1;
      for (let index = 0; index < keybord1.length; index++) {
        keybord1[index] = keybord1[index].toUpperCase();
      }


      this.setData({
        show: !this.data.show,
        value,
        keybord1,
        endLen: index
      });
    },
    getFocusop(e) {
      let {
        value
      } = e.detail
      let fouted = value.toUpperCase().split('')
      if (fouted.length == 6) {
        this.setData({
          titleAfter: true
        })
      } else {
        this.setData({
          titleAfter: false
        })
      }
      this.setData({
        value1: fouted
      })
    },
    show1() {
      this.setData({
        show1: !this.data.show1,
      });
    },
  },
});